home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbm / pbmto10x.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-06  |  3.1 KB  |  128 lines

  1. /* pbmto10x.c - read a portable bitmap and produce a Gemini 10X printer file
  2. **
  3. ** Copyright (C) 1990 by Ken Yap
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "pbm.h"
  14.  
  15. #define    LOW_RES_ROWS    8        /* printed per pass */
  16. #define    HIGH_RES_ROWS    16        /* printed per pass */
  17.  
  18. static void res_60x72 ARGS(( void ));
  19. static void res_120x144 ARGS(( void ));
  20.  
  21. static int    highres = 0;
  22. static FILE    *ifp;
  23. static int    rows, cols, format;
  24.  
  25. void
  26. main(argc, argv)
  27.     int    argc;
  28.     char    *argv[];
  29. {
  30.     pbm_init( &argc, argv );
  31.     if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
  32.     {
  33.         highres = 1;
  34.         --argc;
  35.         ++argv;
  36.     }
  37.     if (argc > 2)
  38.         pm_usage("[pbmfile]");
  39.     if (argc == 2)
  40.         ifp = pm_openr(argv[1]);
  41.     else
  42.         ifp = stdin;
  43.  
  44.     pbm_readpbminit(ifp, &cols, &rows, &format);
  45.     if (highres)
  46.         res_120x144();
  47.     else
  48.         res_60x72();
  49.  
  50.     pm_close(ifp);
  51.     pm_close (stdout);
  52.     exit(0);
  53. }
  54.  
  55. static void
  56. res_60x72()
  57. {
  58.     register int    i, item, npins, row, col;
  59.     bit        *bitrows[LOW_RES_ROWS], *bP[LOW_RES_ROWS];
  60.  
  61.     for (i = 0; i < LOW_RES_ROWS; ++i)
  62.         bitrows[i] = pbm_allocrow(cols);
  63.     fprintf (stdout, "\033A\010");        /* '\n' = 8/72 */
  64.     for (row = 0; row < rows; row += LOW_RES_ROWS)
  65.     {
  66.         if (row + LOW_RES_ROWS <= rows)
  67.             npins = LOW_RES_ROWS;
  68.         else
  69.             npins = rows - row;
  70.         for (i = 0; i < npins; ++i)
  71.             pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
  72.         fprintf (stdout, "\033K%c%c", cols % 256, cols / 256);
  73.         for (col = 0; col < cols; ++col)
  74.         {
  75.             item = 0;
  76.             for (i = 0; i < npins; ++i)
  77.                 if (*(bP[i]++) == PBM_BLACK)
  78.                     item |= 1 << (7 - i);
  79.             putchar(item);
  80.         }
  81.         putchar('\n');
  82.     }
  83. }
  84.  
  85. static void
  86. res_120x144()
  87. {
  88.     register int    i, pin, item, npins, row, col;
  89.     bit        *bitrows[HIGH_RES_ROWS], *bP[HIGH_RES_ROWS];
  90.  
  91.     for (i = 0; i < HIGH_RES_ROWS; ++i)
  92.         bitrows[i] = pbm_allocrow(cols);
  93.     putchar('\033'); putchar('3'); putchar('\0');
  94.     for (row = 0; row < rows; row += HIGH_RES_ROWS)
  95.     {
  96.         if (row + HIGH_RES_ROWS <= rows)
  97.             npins = HIGH_RES_ROWS;
  98.         else
  99.             npins = rows - row;
  100.         for (i = 0; i < npins; ++i)
  101.             pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
  102.         fprintf (stdout, "\033L%c%c", cols % 256, cols / 256);
  103.         for (col = 0; col < cols; ++col)
  104.         {
  105.             item = 0;
  106.             /* even rows */
  107.             for (pin = i = 0; i < npins; i += 2, ++pin)
  108.                 if (*(bP[i]++) == PBM_BLACK)
  109.                     item |= 1 << (7 - pin);
  110.             putchar(item);
  111.         }
  112.         putchar('\n');            /* flush buffer */
  113.         fprintf (stdout, "\033J\001");        /* 1/144 down */
  114.         fprintf (stdout, "\033L%c%c", cols % 256, cols / 256);
  115.         for (col = 0; col < cols; ++col)
  116.         {
  117.             item = 0;
  118.             /* odd rows */
  119.             for (i = 1, pin = 0; i < npins; i += 2, ++pin)
  120.                 if (*(bP[i]++) == PBM_BLACK)
  121.                     item |= 1 << (7 - pin);
  122.             putchar(item);
  123.         }
  124.         putchar('\n');            /* flush buffer */
  125.         fprintf (stdout, "\033J\017");        /* 15/144 down */
  126.     }
  127. }
  128.